package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.bean.SetmealDish;
import com.itheima.dao.SetmealDishDao;
import com.itheima.service.SetmealDishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SetmealDishServiceImpl implements SetmealDishService {

    @Autowired
    private SetmealDishDao setmealDishDao;

    /**
     * 添加套餐菜品数据
     * @param setmealDish
     * @return
     */
    @Override
    public int add(SetmealDish setmealDish) {
        return setmealDishDao.insert(setmealDish);
    }

    /**
     * 根据套餐的id来删除菜品数据
     *
     * @param setmealId
     * @return
     */
    @Override
    public int deleteBySetmealId(long setmealId) {

        //1. 构建条件对象
        LambdaQueryWrapper<SetmealDish> qw = new LambdaQueryWrapper<>();

        //2. 设置条件
        qw.eq(SetmealDish::getSetmealId , setmealId);

        //3. 删除
        return setmealDishDao.delete(qw);
    }
    @Override
    public List<SetmealDish> list(LambdaQueryWrapper<SetmealDish> queryWrapper) {
        return setmealDishDao.selectList(queryWrapper);
    }
}
